package com.example.demo.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.convert.PointsConvert;
import com.example.demo.domain.base.PageParam;
import com.example.demo.domain.base.PageResult;
import com.example.demo.domain.entity.CheckInDO;
import com.example.demo.domain.param.CheckInCreateParam;
import com.example.demo.domain.param.CheckInUpdateParam;
import com.example.demo.domain.vo.CheckInVO;
import com.example.demo.dao.CheckInMapper;
import com.example.demo.service.CheckInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * CheckInServiceImpl
 *
 * @author haochen78
 * @date 2025/10/3 21:19
 **/
@Service
public class CheckInServiceImpl implements CheckInService {

    @Autowired
    private CheckInMapper checkInMapper;

    @Override
    public PageResult<CheckInVO> listCheckIns(PageParam param) {
        Page<CheckInDO> page = checkInMapper.selectPage(new Page<>(param.getPageNum(), param.getPageSize()), null);
        Page<CheckInVO> pageInfo = PointsConvert.INSTANCE.checkInDoToVoPage(page);
        return new PageResult<>(pageInfo);
    }

    @Override
    public void checkInAdd(CheckInCreateParam param) {
        CheckInDO checkInDO = PointsConvert.INSTANCE.checkInParamToDo(param);
        checkInMapper.insert(checkInDO);
    }

    @Override
    public void checkInUpdate(CheckInUpdateParam param) {
        CheckInDO checkInDO = PointsConvert.INSTANCE.checkInParamToDo(param);
        checkInMapper.updateById(checkInDO);
    }

    @Override
    public void checkInDelete(Long id) {
        checkInMapper.deleteById(id);
    }
}
